`timescale 1ns/100ps
module clockTop_tb;

reg           t_rstn    ;
reg           t_clk     ;

reg           t_setTime ;
reg           t_setHour ;
reg           t_setMin  ;
reg           t_setAM_PM;
reg           t_alarm   ;
reg           t_toggle  ;

wire [13:0]   t_dispHour;
wire [13:0]   t_dispMin ;
wire [13:0]   t_dispSec ;
wire          t_AM_PM   ;
wire          t_speaker ;

integer h;
integer m;
initial begin
/***************************** initial *****************************/
    t_rstn      <=  1'b0;
    t_clk       <=  1'b0;

    t_setTime   <=  1'b0;
    t_setHour   <=  1'b0;
    t_setMin    <=  1'b0;
    t_setAM_PM  <=  1'b0;
    t_alarm     <=  1'b0;
    t_toggle    <=  1'b0;
    #1
    t_rstn      <=  1'b1;
/************** begin to set alarm, ring at 01:30 am ***************/
    #3598
    t_alarm     <=  1'b1;
    t_setHour   <=  1'b1;
    #2
    t_setHour   <=  1'b0;
    for(m = 0; m < 60; m = m + 1) begin
        t_setMin    <=  ~t_setMin;
        #1;
    end
    t_alarm     <=  1'b0;
    t_toggle    <=  1'b1;       // turn on the alarm
/*******************************************************************/
/*********************** begin to set time *************************/
    #58
    t_setTime   <=  1'b1;
    for(m = 0; m < 58; m = m + 1) begin
        t_setMin    <=  ~t_setMin;
        #1;
    end
    t_setTime   <=  1'b0;
/*******************************************************************/
    #4000
    $finish;
end

always #1   t_clk <= ~t_clk;

clockTop clockTop_inst(
    .rstn       (       t_rstn          ),
    .clk        (       t_clk           ),

    .setTime    (       t_setTime       ),
    .setHour    (       t_setHour       ),
    .setMin     (       t_setMin        ),
    .setAM_PM   (       t_setAM_PM      ),
    .alarm      (       t_alarm         ),
    .toggle     (       t_toggle        ),

    .dispHour   (       t_dispHour      ),
    .dispMin    (       t_dispMin       ),
    .dispSec    (       t_dispSec       ),
    .AM_PM      (       t_AM_PM         ),
    .speaker    (       t_speaker       )
);

endmodule